package com.example.feifei.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.example.feifei.bean.PieChatBean;
import com.example.feifei.newproject.R;
import com.example.feifei.view.lear.DrawView;
import com.example.feifei.view.gif.GifView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by feifei on 2017/12/4.
 */

public class MineFragment extends Fragment implements View.OnClickListener{

    private View root_view;

    private Button btn_timepicker;
    private TextView text_selectTime;
    private GifView mygifView;

    private DrawView layout_pie;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        root_view = inflater.inflate(R.layout.fragment_mine,null);
        initView();
        return root_view;

    }

    private void initView(){
        btn_timepicker = (Button) root_view.findViewById(R.id.btn_timepicker);
        btn_timepicker.setOnClickListener(this);
        text_selectTime = (TextView) root_view.findViewById(R.id.text_selectTime);
        layout_pie = (DrawView) root_view.findViewById(R.id.layout_pie);
        layout_pie.setStartAngle(10);
        layout_pie.setPieData(getPieData());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            //时间选择
            case R.id.btn_timepicker:
                //时间选择器
                TimePickerView pvTime = new TimePickerView.Builder(getContext(), new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {//选中事件回调
//                        tvTime.setText(getTime(date));
                        text_selectTime.setText(date.getYear());
                    }
                })
                        .isCenterLabel(false)
                .build();
                pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
                pvTime.show();
                break;
        }
    }

    private List<PieChatBean> getPieData(){
        List<PieChatBean> pieList = new ArrayList<>();
        for(int i= 0;i<6;i++){
            PieChatBean bean = new PieChatBean(i);
            pieList.add(bean);
        }
        return  pieList;
    }
}
